/**
 * 封装本地存储模块
 * 两个参数:
 * 1. 键 key
 * 2. 值 value
 */

class Storage {
  // 🌈 将TOKEN到本地存储

  setItem = (key, value) => {
    if (typeof value === 'object') {
      value = JSON.stringify(value)
    }
    window.localStorage.setItem(key, value)
  }

  // 🌈 获取本地存储的TOKEN
  getItem = key => {
    const data = window.localStorage.getItem(key)
    try {
      return JSON.parse(data)
    } catch (error) {
      return data
    }
  }

  // 🌈 删除本地存储的TOKEN
  removeItem = key => {
    window.localStorage.removeItem(key)
  }
}

export default new Storage()
